#include <stdio.h>
#include <string.h> // 为了使用 strlen 函数

#define MAX_NAME_LENGTH 10

int main() {
    int n;
    scanf("%d", &n);
    char girl[n/2][MAX_NAME_LENGTH];
    char boy[n/2][MAX_NAME_LENGTH];
    int a[n];
    int girl_count = 0, boy_count = 0;
    
    for (int i = 0; i < n; i++) {
        int x;
        char y[MAX_NAME_LENGTH];
        scanf("%d %s", &x, y);
        
        int len = strlen(y);
        if (len >= MAX_NAME_LENGTH) {
            len = MAX_NAME_LENGTH - 1;
        }
        
        if (x == 0) {
            strncpy(girl[girl_count], y, len);
            girl[girl_count][len] = '\0';
            girl_count++;
        } else {
            strncpy(boy[boy_count], y, len);
            boy[boy_count][len] = '\0';
            boy_count++;
        }
        a[i] = x;
    }
    
    int aa = 0;
    int bb = 0;
    for (int i = 0; i < n/2; i++) {
        if (a[i] == 0) {
            printf("%s %s\n", girl[aa], boy[n/2-aa-1]);
            aa++;
        } else {
            printf("%s %s\n", boy[bb], girl[n/2-bb-1]);
            bb++;
        }
    }
    return 0;
}